#动作相似度计算
import numpy as np
import math

#image
image = np.array([400.00,69.56521739, 400.00 ,173.91304348 ,313.04347826,
 173.91304348 ,243.47826087, 243.47826087, 243.47826087 ,330.43478261,
 486.95652174, 173.91304348 ,539.13043478 ,260.86956522 ,539.13043478,
 347.82608696, 347.82608696, 400.00   ,      347.82608696, 556.52173913,
 347.82608696, 730.43478261 ,452.17391304 ,400.00,         452.17391304,
 556.52173913, 452.17391304 ,730.43478261, 382.60869565 , 52.17391304,
 417.39130435,  52.17391304 ,365.2173913 ,  69.56521739 ,434.7826087,
  69.56521739, 765.2173913 ,  17.39130435])

for i in range(0,len(image),2):
    image[i] = image[i] - 400.00

for j in range(1,len(image),2):
    image[j] = image[j] - 173.91304348

img = image.reshape(-1)
#print(img)

#image8
image8 = np.array([114.7826087 ,  78.26086957, 114.7826087 , 109.56521739  ,88.69565217,
 109.56521739 , 73.04347826, 148.69565217, 120.00,         117.39130435,
 135.65217391, 109.56521739, 161.73913043 ,148.69565217, 120.00,
 125.2173913 ,  99.13043478 ,180.00,       125.2173913 , 266.08695652,
 114.7826087 , 328.69565217 ,125.2173913,  180.00,         120.00,
 258.26086957, 114.7826087,  328.69565217 ,109.56521739 , 70.43478261,
 120.00,          70.43478261, 104.34782609,  78.26086957 ,125.2173913,
  78.26086957 ,229.56521739, 336.52173913])
for i in range(0,len(image8),2):
    image8[i] = image8[i] - 114.7826087

for j in range(1,len(image8),2):
    image8[j] = image8[j] - 109.56521739
 
img8 = image8.reshape(-1)
#print(img8)

#image9
image9 = np.array([ 417.39130435,286.95652174,417.39130435,391.304347833,47.82608696,
  391.30434783,295.65217391,495.65217391,313.04347826 , 573.91304348,
  486.95652174 , 391.30434783,  521.73913043 , 495.65217391,  486.95652174,
  600.00,          365.2173913 ,  600.00,      330.43478261 , 808.69565217,
  313.04347826,  991.30434783,  452.17391304 , 626.08695652,  469.56521739,
  808.69565217, 486.95652174 ,1017.39130435 , 400.000,          260.86956522,
  417.39130435 , 286.95652174 , 382.60869565  ,286.95652174,  452.17391304,
  286.95652174 , 765.2173913 ,   26.08695652])
for i in range(0,len(image9),2):
    image9[i] = image9[i] - 417.39130435

for j in range(1,len(image9),2):
    image9[j] = image9[j] - 391.304347833
 
img9 = image9.reshape(-1)
#print(img9)


# 计算余弦相似度
#image and image8
sum08 = 0
sq0 = 0
sq8 = 0
for i in range(len(img)):
	sum08 += img[i] * img8[i]
	sq0 += pow(img[i], 2)
	sq8 += pow(img8[i], 2)
    
try:
	result08 = round(float(sum08) / (math.sqrt(sq0) * math.sqrt(sq8)), 2)
except ZeroDivisionError:
    result08 = 0.0

print('The similarity between image and image8 is')
print(result08)

#image and image9
sum09 = 0
#sq0 = 0
sq9 = 0
for i in range(len(img)):
	sum09 += img[i] * img9[i]
	#sq0 += pow(img[i], 2)
	sq9 += pow(img9[i], 2)
    
try:
	result09 = round(float(sum09) / (math.sqrt(sq0) * math.sqrt(sq9)), 2)
except ZeroDivisionError:
    result09 = 0.0

print('The similarity between image and image9 is')
print(result09)